#ifndef _INIT_PERIPHERAL_H_
#define _INIT_PERIPHERAL_H_
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <protocentral_Max30003.h>
#include <SparkFun_LIS2DH12.h>
#include <SparkFun_ST25DV64KC_Arduino_Library.h>
#include "FDC2214.h"
#include "MAX30105.h"
#include <ESP32_SoftWire.h>
#include <spo2_algorithm.h>

/* POWER GPIO PIN */
#define OUTPUT_3V3_PIN  12
#define OUTPUT_1V8_PIN  33
#define OUTPUT_5V_PIN   32

/* ST25DV GPIO PIN */
#define ST25DV_SDA  26
#define ST25DV_SCLK 25
#define ST25DV_GPO  37

/* LIS2DH12 GPIO PIN */
#define LIS2DH12_SDA  21
#define LIS2DH12_SCLK  22

/* MAX30101 GPIO PIN */
#define MAX30101_SDA_PIN  4
#define MAX30101_SCL_PIN  2

/* NFC field */
#define FIELD_FALLING 0   //RF场下降
#define FIELD_RISING  1   //RF场上升
#define FIELD_UNDEF   2   

/* Dynamic Registers i2c address */
/** @brief ST25DV GPO dynamic register address. */
#define ST25DV_GPO_DYN_REG                   0x2000
/** @brief ST25DV Energy Harvesting control dynamic register address. */
#define ST25DV_EH_CTRL_DYN_REG               0x2002
/** @brief ST25DV RF management dynamic register address. */
#define ST25DV_RF_MNGT_DYN_REG               0x2003
/** @brief ST25DV I2C secure session opened dynamic register address. */
#define ST25DV_I2C_SSO_DYN_REG               0x2004
/** @brief ST25DV Interrupt status dynamic register address. */
#define ST25DV_ITSTS_DYN_REG                 0x2005
/** @brief ST25DV Mailbox control dynamic register address. */
#define ST25DV_MB_CTRL_DYN_REG               0x2006
/** @brief ST25DV Mailbox message length dynamic register address. */
#define ST25DV_MBLEN_DYN_REG                 0x2007
/** @brief ST25DV Mailbox buffer address. */
#define ST25DV_MAILBOX_RAM_REG               0x2008

#pragma pack(1)
struct Button {
    const uint8_t PIN;
    uint32_t numberKeyPresses;
    bool pressed;
};
#pragma pack()

#define SMARTAG_END_ADDR_COMPACT_DATA   8192
#define SMARTAG_BEGIN_ADDR_COMPACT_DATA 120
#define LAST_TIMESTAMP  108
#define LAST_ADDRESS    112
#define WORKING_MODE    116

extern uint16_t LastSamplePointer;
extern bool nfc_write_notify;
extern uint32_t RFActivityStatus;
extern volatile uint32_t RFActivity;
extern Button button1;

extern MAX30003 max30003;
extern FDC2214 capsense;
extern SFE_ST25DV64KC_NDEF tag;
extern SPARKFUN_LIS2DH12 accel;
extern MAX30105 _particleSensor;
extern SoftWire _Wire_MAX30101;

void init_power(void);
void deinit_power(void);
void max30003_Init(void);
void lis2dh12_init(void);
void fdc2214_init(void);
void st25dv64_init(void);
void init_max30101(void);

float readADC_Avg(void);

#endif
